package com.kingyea.app.market.appExtendInfo.service.impl;

import com.kingyea.app.market.appExtendInfo.bean.AppExtendInfo;
import com.kingyea.app.market.appExtendInfo.dao.AppExtendInfoMapper;
import com.kingyea.app.market.appExtendInfo.service.AppExtendInfoService;
import com.kingyea.app.market.utils.StateCode;
import com.kingyea.mobilepolice.system.exception.BusinessException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author
 * @version v1.0.0
 * @description AppExtendInfo 实现类
 * @date Created in 2018-02-10 16:11:06
 */
@Service
@Transactional
public class AppExtendInfoServiceImpl implements AppExtendInfoService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AppExtendInfoServiceImpl.class);

    @Resource
    private AppExtendInfoMapper appExtendInfoMapper;

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @Override
    public AppExtendInfo getById(String id) throws Exception {
        return this.appExtendInfoMapper.getById(id);
    }

    /**
     * 列表
     *
     * @param
     * @return
     */
    @Override
    public Object list(AppExtendInfo appExtendInfo) throws Exception {
        Object list = appExtendInfoMapper.list(appExtendInfo);
        return list;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    public int deleteById(String id) throws Exception {
        appExtendInfoMapper.deleteById(id);
        return 1;
    }

    /**
     * 保存
     *
     * @param appExtendInfo
     * @return
     */
    @Override
    public AppExtendInfo save(AppExtendInfo appExtendInfo) throws Exception {
        if (org.springframework.util.StringUtils.isEmpty(appExtendInfo.getAppCode())) {
            throw new BusinessException(StateCode.NO_ARGUMENT_ERROR);
        }
        if (getByAppCode(appExtendInfo.getAppCode()) != null) {
            throw new BusinessException(StateCode.SERVER_DATA_DUPLICATE_ERROR);
        }
        appExtendInfoMapper.save(appExtendInfo);
        return appExtendInfo;
    }

    /**
     * 更新
     *
     * @param appExtendInfo
     * @return
     */
    @Override
    public AppExtendInfo update(AppExtendInfo appExtendInfo) throws Exception {
        if (StringUtils.isBlank(appExtendInfo.getAppCode())) {
            throw new BusinessException(StateCode.NO_ARGUMENT_ERROR);
        }
        appExtendInfo.setUpdateDate(new Date());
        appExtendInfoMapper.update(appExtendInfo);
        return appExtendInfo;
    }

    @Override
    public void test(AppExtendInfo appExtendInfo) {

    }

    @Override
    public AppExtendInfo getByAppCode(String code) throws Exception {
        // TODO Auto-generated method stub
        return appExtendInfoMapper.getByAppCode(code);
    }

    @Override
    public List<AppExtendInfo> getList(Map<String, Object> map) throws Exception {
        return appExtendInfoMapper.getList(map);
    }

    @Override
    public Object deletesByAppCode(String appCode) throws Exception {
        if (org.apache.commons.lang3.StringUtils.isBlank(appCode)) {
            throw new BusinessException(StateCode.NO_ARGUMENT_ERROR);
        }
        return appExtendInfoMapper.deletesByAppCode(appCode);
    }
}
